#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) {
        int ret = 0;
        for (int i = 0; i < timeSeries.size(); i++)
        {
            // if (i > 0 && timeSeries[i - 1] == timeSeries[i])
            //     continue;

            ret++;
            if (i > 0)
            {
                ret += min(duration - 1, timeSeries[i] - timeSeries[i - 1] - 1);
            }
        }
        ret += duration - 1;

        return ret;
    }
};